package org.wangle.seckill.controller;



import com.alibaba.csp.sentinel.annotation.SentinelResource;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.data.repository.query.Param;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.wangle.api.goods.pojo.Goods;
import org.wangle.api.order.provider.OrdersProvider;
import org.wangle.api.properties.MQ.SecKillProperties;
import org.wangle.api.user.pojo.User;
import org.wangle.seckill.service.SecKillService;
import org.wangle.starter.lock.annotation.RedisLock;

import javax.annotation.Resource;

@RestController
@RequestMapping("goods")
public class SecKillController {

    @Resource
    private SecKillService secKillService;

    @Reference
    private OrdersProvider ordersProvider;



    @GetMapping("/secKill")
    @RedisLock(key = SecKillProperties.goods_key)
    @SentinelResource(value = "secKill")
    public Object secKill(@Param("userId") Integer userId,@Param("goodsId") Integer goodsId){
        User user = new User();
        user.setId(userId);
        Goods goods = new Goods();
        goods.setId(goodsId);
        return secKillService.secKill(user,goods);
    }

    @RequestMapping("/testDubbo")
    public Object aaa(){
        return ordersProvider.creatOrder(new User(), new Goods());
    }



    
}
